<?php 
class ControllerContentItem extends Controller {
	public function index(){	       			
        $this->language->load('content/content');
        $this->data['template'] = $this->config->get('config_template');           
        $this->data['heading_title'] = $this->language->get('item_heading_title');   
        
        $this->document->title = $this->language->get('item_heading_title');
        $this->document->keywords = $this->config->get('config_meta_keywords');
        $this->document->description = $this->config->get('config_meta_description');
        
		$this->document->breadcrumbs = array();		
      	$this->document->breadcrumbs[] = array(
        	'href'      => HTTP_SERVER . 'index.php?route=common/home',
        	'text'      => $this->language->get('text_home'),
        	'separator' => FALSE
      	);		
		
        $content_id = isset($this->request->get['content_id']) ? $this->request->get['content_id'] : 0;
        $this->load->model('content/content');		       
        $content = $this->model_content_content->getContent($content_id);

		if($content){
            $this->document->title = $content['meta_title'] ? $content['meta_title'] : $content['name'];
            $this->document->keywords = $content['meta_keywords'];
            $this->document->description = $content['meta_description'];
        
            $this->data['heading_title'] = $content['name']; 
            $this->load->model('tool/image');
            
            $this->data['title'] = $content['name'];
            $this->data['short_title'] = (strlen($content['name']) > 72) ? (mb_substr($content['name'], 0, 72) . ' ...') : $content['name']; 
            //$this->data['image'] = $this->model_tool_image->resize($content['image'], 469, 248);
            $this->data['image'] = $this->model_tool_image->resize($content['image'], 255, 248);
            
            $text = str_replace('{READ_MORE}', '', $content['description']);   
            $this->data['text'] = str_replace('<hr />', '', html_entity_decode($text));
            
            $this->data['send_link'] = HTTP_SERVER . 'index.php?route=content/item&itemid=' . $content_id;
            $this->data['news_link'] = HTTP_SERVER . 'index.php?route=content/list'; 
            $this->data['tell_friend'] = HTTP_SERVER . 'index.php?route=content/tellfriend';               
                
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/content/item.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/content/item.tpl';
			} 
            else {
				$this->template = 'default/template/content/item.tpl';
			}
			
			$this->children = array(
				'common/header',
				'common/footer',
				'common/column_left',				
			);		
			
	  		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
    	} 
        else {      	
	  		$this->document->title = $this->language->get('item_heading_title');
            $this->data['heading_title'] = $this->language->get('item_heading_title');
      		$this->data['text_empty'] = $this->language->get('text_item_empty');
            $this->data['template'] = $this->config->get('config_template');

			if(file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/content/item.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/content/item.tpl';
			} 
            else{
				$this->template = 'default/template/content/item.tpl';
			}
			
			$this->children = array(
				'common/header',
				'common/footer',
				'common/column_left',				
			);	
		
	  		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
    	}
  	}
	
    public function article(){                       
        $this->language->load('content/content');
        $this->data['template'] = $this->config->get('config_template');            
        $this->data['heading_title'] = $this->language->get('item_heading_title');   
        
        $this->document->title = $this->language->get('item_heading_title');
        $this->document->keywords = $this->config->get('config_meta_keywords');
        $this->document->description = $this->config->get('config_meta_description');
        
        $this->document->breadcrumbs = array();        
          $this->document->breadcrumbs[] = array(
            'href'      => HTTP_SERVER . 'index.php?route=common/home',
            'text'      => $this->language->get('text_home'),
            'separator' => FALSE
          );        
        
        $content_id = isset($this->request->get['content_id']) ? $this->request->get['content_id'] : 0;
        $this->load->model('content/content');               
        $content = $this->model_content_content->getContent($content_id);        
        
        $categories = $this->model_content_content->getContentCategoriesList($content_id);                                      
        $this->data['categories'] = $categories;
        
        if($content){
            $this->document->title = $content['meta_title'] ? $content['meta_title'] : $content['name'];
            $this->document->keywords = $content['meta_keywords'];
            $this->document->description = $content['meta_description'];
            
            $this->data['heading_title'] = $content['name']; 
            $this->load->model('tool/image');
            
            $this->data['title'] = $content['name'];
            $this->data['short_title'] = (strlen($content['name']) > 72) ? (mb_substr($content['name'], 0, 72) . ' ...') : $content['name']; 
            $this->data['image'] = $this->model_tool_image->resize($content['image'], 469, 248);
            
            $text = str_replace('{READ_MORE}', '', $content['description']);   
            $this->data['text'] = str_replace('<hr />', '', html_entity_decode($text));   
            
            $this->data['send_link'] = HTTP_SERVER . 'index.php?route=content/item&itemid=' . $content_id;
            $this->data['news_link'] = HTTP_SERVER . 'index.php?route=content/list'; 
            $this->data['tell_friend'] = HTTP_SERVER . 'index.php?route=content/tellfriend';            
            $this->data['back_link'] = HTTP_SERVER . 'index.php?route=common/home'; 
                
            if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/content/info_home.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/content/info_home.tpl';
            } 
            else {
                $this->template = 'default/template/content/info_home.tpl';
            }
            
            $this->children = array(
                'common/header',
                'common/footer',
                'common/column_left',                
            );        
            
              $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
        } 
        else {          
              $this->document->title = $this->language->get('item_heading_title');
            $this->data['heading_title'] = $this->language->get('item_heading_title');
              $this->data['text_empty'] = $this->language->get('text_item_empty');

            if(file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/content/item.tpl')) {
                $this->template = $this->config->get('config_template') . '/template/content/item.tpl';
            } 
            else{
                $this->template = 'default/template/content/item.tpl';
            }
            
            $this->children = array(
                'common/header',
                'common/footer',
                'common/column_left',                
            );    
        
              $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
        }
    }
      
	public function loadInfo() {
		$this->load->model('catalog/information');
		if (isset($this->request->get['information_id'])) {
			$information_id = $this->request->get['information_id'];
		} else {
			if (isset($this->request->get['create'])) {
				$information_id = $this->config->get('config_account_id');
			} else {
				$information_id = $this->config->get('config_checkout_id');
			}
		}      
		$information_info = $this->model_catalog_information->getInformation($information_id);

		$output = '
			<div id="content" style="margin: 0pt; padding: 0pt;">
			  <div class="top">
			    <div class="left"></div>
			    <div class="right"></div>
			    <div class="center">
			      <h1>'.$information_info['title'].'</h1>
			    </div>
			  </div>
			  <div class="middle">
			    <p>'.html_entity_decode($information_info['description']).'</p>
			  </div>
			  <div class="bottom">
			    <div class="left"></div>
			    <div class="right"></div>
			    <div class="center"></div>
			  </div>
			</div>';

		$this->response->setOutput($output, $this->config->get('config_compression'));
	}
}
?>